columns = set()
from app.models.po.lugang.lugang_qinshi_po import lugang_qinshi_column

with open("doc") as f:
    while 1:
        line = f.readline()
        if not line:
            break

        tag = line.split(":")[0]
        condition = line.split(":")[1]
        s1 = condition.replace("average(", "").replace(")", "").strip()
        s1_array = s1.split("/")
        left = s1_array[0].split(",")
        right = s1_array[1].split(",")

        columns.update(set(left))
        columns.update(set(right))

column_list = list(columns)
print(column_list)

with open("doc") as f:
    while 1:
        line = f.readline()
        if not line:
            break

        tag = line.split(":")[0]
        condition = line.split(":")[1]
        s1 = condition.replace("average(", "").replace(")", "").strip()
        s1_array = s1.split("/")
        left = s1_array[0].split(",")
        right = s1_array[1].split(",")

        left_index = [column_list.index(i) for i in left]
        right_index = [column_list.index(i) for i in right]

        template = "result['{}'] = get_rate(get_avg({}, group), get_avg({}, group))".format(tag,left_index,right_index)
        template = template.replace(", ",",")
        print(template)